import Home from './components/Home'
import Menu from './components/Menu'
import Admin from './components/Admin'
import About from './components/about/About'
import Login from './components/Login'
import Register from './components/Register'

//二级路由
import Contact from './components/about/Contact'
import History from './components/about/History'
import Delivery from './components/about/Delivery'
import OrderingGuide from './components/about/OrderingGuide'

//三级路由
import Phone from './components/about/contact/Phone'
import PersonName from './components/about/contact/PersonName'

export const routes = [
  {
    path: '/', name: "homeLink", components: {
      default: Home,
      'orderingGuide': OrderingGuide,
      'delivery': Delivery,
      'history': History
    }
  },
  { path: '/menu', name: "menuLink", component: Menu },
  {
    path: '/admin', name: "adminLink", component: Admin,
    //路由独享守卫
    // beforeEnter: (to, from, next) => {
    //   if (to.path == '/login' || to.path == '/register') {
    //     next();
    //   } else {
    //     alert('尚未登录，请先登录！');
    //     next('/login');
    //   }
    // }
  },
  {
    path: '/about', name: "aboutLink", redirect: '/about/contatct', component: About,
    children: [
      {
        path: '/about/contatct', name: 'contactLink', redirect: '/about/contatct/personname', component: Contact,
        children: [
          { path: '/about/contatct/phone', name: 'phoneNumber', component: Phone },
          { path: '/about/contatct/personname', name: 'personName', component: PersonName },
        ]
      },
      { path: '/about/history', name: 'historyLink', component: History },
      { path: '/about/delivery', name: 'deliveryLink', component: Delivery },
      { path: '/about/orderingGuide', name: 'orderingGuideLink', component: OrderingGuide },
    ]
  },
  { path: '/login', name: "loginLink", component: Login },
  { path: '/register', name: "registerLink", component: Register },
  //默认路由，输入错误定向至Home页面
  { path: '*', redirect: '/' },

]

